//
//  ThirdViewController.m
//  lehuotest
//
//  Created by lehuo on 2017/1/17.
//  Copyright © 2017年 QF. All rights reserved.
//

#import "ThirdViewController.h"
#import "LHDownView.h"
#import "LHAlertView.h"
#import "LHPhotoEnumController.h"
#import "LHActionSheet.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
@interface ThirdViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@end

@implementation ThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, kScreenW, kScreenH - 40)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData:) name:@"PostData" object:nil];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 获取选中相片的数据
- (void)getData:(NSDictionary *)info
{
    NSLog(@"info = %@",info);
    NSArray *arr = [[info valueForKey:@"object"] valueForKey:@"Data"];
    [LHAlertView showSimpleInfo:[NSString stringWithFormat:@"你选中了%zd张图片",arr.count]];
}


- (IBAction)chageUI:(id)sender
{
    if (_tableView) {
        [_tableView removeFromSuperview];
        _tableView = nil;
    }else
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, kScreenW, kScreenH - 40)];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [self.view addSubview:_tableView];
    }
}
- (IBAction)exit:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (IBAction)alertViewOne:(id)sender
{
    [LHAlertView showSimpleInfo:@"继续拖动查看图文详情"];
}
- (IBAction)alertViewTwo:(id)sender
{
 [LHAlertView showAlertViewWith:@"温馨提示" body:@"给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧" closeTitle:@"寡人知道了" block:^{
     NSLog(@"给俺们一个评分吧");
 }];
}
- (IBAction)alertViewThree:(id)sender
{
    [LHAlertView showAlertViewWith:@"温馨提示" body:@"给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧给俺们一个评分吧" cancelTitle:@"寡人知道了" sureTitle:@"马上就去" block:^(NSUInteger index) {
        NSLog(@"index = %zd",index);
    }];
}
- (IBAction)ActionSheet:(id)sender
{
   [LHActionSheet showActionSheetWithTitle:@"退出后不会删除任何历史数据,下次登录依然可以使用本账号." destructiveTitle:@"退出登录" otherTitles:nil block:^(NSUInteger index) {
       NSLog(@"index = %zd",index);
   }];
}

- (IBAction)camera:(id)sender
{
    LHPhotoEnumController *enumVC = [[LHPhotoEnumController alloc] initWithBlock:^(UIImage *img) {
        self.imgView.image = img;
    }];
    [self presentViewController:enumVC animated:YES completion:nil];
}

- (IBAction)album:(id)sender
{
    LHPhotoEnumController *enumVC = [[LHPhotoEnumController alloc] initWithBlock:nil];
    [self presentViewController:enumVC animated:YES completion:nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.backgroundColor = [UIColor redColor];
    for (UIView *view in [cell subviews]) {
        if ([view isKindOfClass:[UIButton class]]) {
            NSLog(@"gggg");
            return cell;
        }
        
    }
    
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    [button setTitle:@"test" forState:UIControlStateNormal];
    [cell addSubview:button];
    
    
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(kScreenW - 100, 0, 100, 50)];
    [button1 setTitle:@"testOne" forState:UIControlStateNormal];
    [cell addSubview:button1];
    
    [button addTarget:self action:@selector(testOne:) forControlEvents:UIControlEventTouchUpInside];
    button1.backgroundColor = [UIColor greenColor];
    button.backgroundColor = [UIColor greenColor];
    [button1 addTarget:self action:@selector(testThree:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (void)testThree:(UIButton *)sender
{
    UIWindow *window  = [[UIApplication sharedApplication].delegate window];
    CGRect frame = [sender convertRect:sender.bounds toView:window];
    
    
    
    NSLog(@"frame = %@",NSStringFromCGRect(frame));
    
    //    [[LHDownView shareManager] shownDownViewWithView:sender optionTitle:@[@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour"]];
    [LHDownView shownDownViewWithView:sender optionTitle:@[@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour",@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour"] Block:^(NSUInteger index) {
        [LHAlertView showSimpleInfo:[NSString stringWithFormat:@"你点击了第%zd项",index]];
    }];
}

- (void)testOne:(UIButton *)sender
{
    //    UIWindow *window  = [[UIApplication sharedApplication].delegate window];
    //    CGRect frame = [sender convertRect:sender.bounds toView:window];
    //    NSLog(@"frame = %@",NSStringFromCGRect(frame));
    //    [LHDownView shownDownViewWithView:sender optionTitle:@[@"MenuOne",@"MenuTwo",@"MenuThree",@"MenuFour"] Block:^(NSUInteger index) {
    //            [LHAlertView showSimpleInfo:[NSString stringWithFormat:@"你点击了第%zd项",index]];
    //    }];
    
    [LHDownView shownDownViewWithView:sender optionTitle:@[@"消息",@"首页",@"搜索",@"分享"] images:@[@"Pokemon_Go_01",@"Pokemon_Go_02",@"Pokemon_Go_03",[UIImage imageNamed:@"Pokemon_Go_01"],@"Pokemon_Go_01",@"Pokemon_Go_02",@"Pokemon_Go_03",@"Pokemon_Go_04"] Block:^(NSUInteger index) {
        [LHAlertView showSimpleInfo:[NSString stringWithFormat:@"你点击了第%zd项",index]];
    }];
    
    
    
}
@end
